package com.daoImpl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.dao.ManagerDao;
import com.model.Manager;

@Component("managerDao")
public class ManagerDaoImpl implements ManagerDao {

	private HibernateTemplate hibernateTemplate;
	public void addMananger(Manager manager) {
		hibernateTemplate.save(manager);
		
	}

	public void deleteMananger(Manager manager) {
		hibernateTemplate.delete(manager);

	}

	public void updateManager(Manager manager) {
		hibernateTemplate.update(manager);

	}

	public boolean exists(Manager manager) {
		List list=hibernateTemplate.find("from Manager m where m.account='"+manager.getAccount()+"' ");
		
		if(list.size()>0&&list!=null){
			System.out.println(list.size());
			return true;
		}
		else return false;
	}

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}
	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public Manager loadMananger(String account, String password) {
		List<Manager> list=this.hibernateTemplate.find("from Manager m where m.account='"+account+"' and m.password='"+password+"'");
		if(list!=null&&list.size()>0){
			return list.get(0);
		}
		else{
			return null;
		}
	}

	public List<Manager> getManagerList(String hql) {
		return this.hibernateTemplate.find(hql);
	}

	
}
